package com.example.semo.controller;

import com.example.semo.dao.ImgDao;
import com.example.semo.entity.Params;
import com.example.semo.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@ResponseBody
public class ImgController {
    String msg;
    int code;
    @Autowired
    ImgDao imgDao;
    //查询首页图片
    @RequestMapping("/selectImg")
    public JsonResult selectImg(@RequestBody Params params){
        params.setPageNo((params.getPageNo()-1) * params.getPageSize());
        List list =imgDao.SelectImg(params);
        int count=imgDao.SelectCount();
        list.add(count);
        if(null == list || list.size()==0){
            code=500;
            msg="数据为空";
        }else{
            code=200;
            msg="查询首页图片成功";
        }
        return new JsonResult(200,msg, list);
    }
    //查询分类列表图片
    @RequestMapping("/selectCateImg")
    public JsonResult selectCateImg(@RequestBody Params params){
        params.setPageNo((params.getPageNo()-1) * params.getPageSize());
        List list =imgDao.SelectCateImg(params);
        list.add(list.size());
        if(null == list || list.size()==0){
            code=500;
            msg="数据为空";
        }else{
            code=200;
            msg="查询分类列表图片成功";
        }
        return new JsonResult(200,msg, list);
    }

    //查询分类列表图片
    @RequestMapping("/selectFeatCateImg")
    public JsonResult selectFeatCateImg(@RequestBody Params params){
        params.setPageNo((params.getPageNo()-1) * params.getPageSize());
        List list =imgDao.SelectFeatCateImg(params);
        list.add(list.size());
        if(null == list || list.size()==0){
            code=500;
            msg="数据为空";
        }else{
            code=200;
            msg="查询特色分类列表图片成功";
        }
        return new JsonResult(200,msg, list);
    }
}
